// import $H from "@/utils/request.js"
export default {
  state: {
    token: false,
    status: false,
    userInfo: {},
  },
  mutations: {
    // 登陆成功后渲染数据
    login(state, userInfo) {
      state.userInfo = userInfo;
      state.token = userInfo.token;
      state.status = userInfo.status;
      window.sessionStorage.setItem("userInfo", JSON.stringify(userInfo));
      window.sessionStorage.setItem("token", JSON.stringify(userInfo.token));
    },
    // 初始化存储
    initUser(state) {
      let userinfo = window.sessionStorage.getItem("userInfo");
      let userInfo = JSON.parse(userinfo);
      if (userInfo) {
        state.userInfo = userInfo;
        state.token = userInfo.token;
        state.status = userInfo.status;
      }
    },
    // 退出登录删除数据
    loginOut(state) {
      state.userInfo = {};
      state.token = false;
      (state.status = false), window.sessionStorage.removeItem("userInfo");
      window.sessionStorage.removeItem("token");
      window.sessionStorage.removeItem("cart");
    },
  },
  getters: {},
  actions: {},
};
